import 'package:flutter/material.dart';
import 'package:toast/toast.dart';

/// Scaffold

class ScaffoldRote extends StatefulWidget {
  @override
  _ScaffoldRoteState createState() => _ScaffoldRoteState();
}

class _ScaffoldRoteState extends State<ScaffoldRote> {
  int _selectedIndex = 1;
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("App Name"),
        centerTitle: true,
        leading: Builder(builder: (context) {
          return IconButton(
            //自定义图标
            icon: Icon(
              Icons.dashboard,
              color: Colors.white,
            ),
            onPressed: () => {
              //打开抽屉菜单
              Scaffold.of(context).openDrawer()
            },
          );
        }),
        actions: <Widget>[
          //导航右侧菜单
          IconButton(
            icon: Icon(Icons.share),
            onPressed: () {
              Toast.show("分享", context, gravity: Toast.CENTER);
            },
          )
        ],
      ),
      drawer: _MyDrawer(), //抽屉
      bottomNavigationBar: BottomNavigationBar(
        //底部导航
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home")),
          BottomNavigationBarItem(
              icon: Icon(Icons.business), title: Text("Business")),
          BottomNavigationBarItem(
              icon: Icon(Icons.school), title: Text("School")),
        ],
        currentIndex: _selectedIndex,
        fixedColor: Colors.blue,
        onTap: _onItemTapped,
      ),
      floatingActionButton: FloatingActionButton(
        //悬浮按钮
        child: Icon(Icons.add),
        onPressed: _onAdd,
      ),
    );
  }

  // 底部导航点击事件
  _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
      Toast.show("导航点击$index", context);
    });
  }

  // 悬浮按钮
  _onAdd() {
    Toast.show("悬浮按钮", context);
  }
}

class _MyDrawer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 300.0,
      height: double.infinity,
      // color: Colors.white,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
            topRight: Radius.circular(20.0),
            bottomRight: Radius.circular(20.0)),
      ),
      margin: EdgeInsets.only(top: 25.0),
      padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
      child: Column(
        children: <Widget>[
          CircleAvatar(
            backgroundImage: NetworkImage(
                "https://avatars2.githubusercontent.com/u/20411648?s=460&v=4"),
          ),
          ClipOval(
            child: Image.network(
              "https://avatars2.githubusercontent.com/u/20411648?s=460&v=4",
              width: 120.0,
            ),
          )
        ],
      ),
    );
  }
}
